<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 汪利东,2016-04-13 16:16
// +----------------------------------------------------------------------

namespace Admin\Controller;


class AppraiseBookController extends BaseController
{
    public function index()
    {
        $map = array();
        $keywords=I("get.keywords");
        if($keywords!=""){
            $map['book_id']=$keywords;
        }
        $interval_time = I('get.interval_time');
        if (!empty($interval_time)) {
            $time=explode('~',$interval_time);
            $time[0]=$time[0].' 00:00:00';
            $time[1]=$time[1].' 23:59:59';
            $map['a.create_time'] = [
                ['gt',$time[0]],
                ['lt',$time[1]]
            ];
        }

        $count = D('OrderBookApprise')->alias('a')->where($map)->count();// 查询满足要求的总记录数
        $Page = new  \Admin\Common\Page($count, C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $this->assign('page', $show);// 赋值分页输出

        $data = D('OrderBookApprise')->alias('a')
            ->join("left join card c on a.user_id=c.user_id")
            ->where($map)
            ->relation(true)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();

        if(I("get.execl")==1){
            $data = D('OrderBookApprise')->alias('a')
                ->join("left join card c on a.user_id=c.user_id")
                ->where($map)
                ->select();
            $file = excel_export($data);
            ouput_Browser($file);
        }else{
            $this->data = $data;
            $this->display();
        }
    }

    function export(){

        $map = array();
        $keywords=I("get.keywords");
        if($keywords!=""){
            $map['book_id']=$keywords;
        }
        $interval_time = I('get.interval_time');
        if (!empty($interval_time)) {
            $time=explode('~',$interval_time);
            $time[0]=$time[0].' 00:00:00';
            $time[1]=$time[1].' 23:59:59';
            $map['a.create_time'] = [
                ['gt',$time[0]],
                ['lt',$time[1]]
            ];
        }

        $data = D('OrderBookApprise')->alias('a')->join("left join card c on a.user_id=c.user_id")->where($map)->select();
        $file = excel_export($data);
        ouput_Browser($file);
    }
    //隐藏评论
    function apprise_hide(){
        $apprise_id=I("get.apprise_id");
        $Apr=M("order_book_apprise");
        $Apr->where("apprise_id='$apprise_id'")->data(['is_show'=>'0'])->save();
        $this->success("修改成功");
    }
    //显示评论
    function apprise_show(){
        $apprise_id=I("get.apprise_id");
        $Apr=M("order_book_apprise");
        $Apr->where("apprise_id='$apprise_id'")->data(['is_show'=>'1'])->save();
        $this->success("修改成功");
    }

    function doDel(){
        $apprise_id=I("get.apprise_id");
        $Apr=M("order_book_apprise");
        $Apr->where("apprise_id='$apprise_id'")->delete();
        $this->success("删除成功");
    }
}